package dao;

import bean.LoginUser;
import utills.HiveJdbc;

import java.sql.*;

public class QueryLogin {
    static Connection connection;


    public void insert(LoginUser loginUser) {



        try {
            Connection connection = HiveJdbc.getConnection();
            if (connection != null) {
                System.out.println("connect success");
                Statement statement=connection.createStatement();
                String sql="insert into table stu values ("+"'"+loginUser.getID()+"'"+","+"'"+loginUser.getPassword()+"'"+")";
                System.out.println(sql);
                statement.execute(sql);
            }
            else{
                System.out.println("connect fail");
                this.connection = connection;
            }
        } catch (SQLException e) {
            e.printStackTrace();
        }




}
    public boolean search(LoginUser loginUser){
        int flag=0;
        try {
            Connection connection = HiveJdbc.getConnection();
            if (connection != null) {
                System.out.println("connect success");
                String sql="select * from stu where id='"+loginUser.getID()+"'"+"and password='"+loginUser.getPassword()+"'";
                Statement stmt = connection.createStatement();
                ResultSet rs=stmt.executeQuery(sql);
                while(rs.next()) {
                        flag=1;
                        break;

                }
                if (flag==1) return true;
                else return false;
            }

            else {
                System.out.println("connect fail");
                this.connection = connection;
            }


        } catch (SQLException e) {
            e.printStackTrace();
        }

      return false;
    }

}
